﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SimpleTaskManager.WebUI.HtmlHelpers
{
    /// <summary>
    /// Extension methods
    /// </summary>
    public static class Extensions
    {
        /// <summary>
        /// Displays a nullable decimal in percentage format.
        /// If the value is null, then "--" will be returned.
        /// </summary>
        /// <param name="value">The value to display in percentage</param>
        /// <param name="precision">Desired number of decimal places.</param>
        /// <returns></returns>
        public static string ToPercentage(this decimal? value, int precision = 2)
        {
            if (value == null) return "--";

            return ((decimal)value).ToString("P"+precision.ToString());
        }
    }
}